using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
	public class T_Report_Change_AreaUnit_Adjust : DBInteractionBase
	{
		#region Class Member Declarations
			private SqlInt32		_report_Change_AreaUnit_AdjustID;
			private SqlGuid			_report_Change_AreaUnit_MainID, _report_Change_AreaUnit_ID;
		#endregion


		public T_Report_Change_AreaUnit_Adjust()
		{
			// Nothing for now.
		}


	


		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Change_AreaUnit_Adjust_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_Change_AreaUnit_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_Change_AreaUnit_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_Change_AreaUnit_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_Change_AreaUnit_MainID));
				cmdToExecute.Parameters.Add(new SqlParameter("@iReport_Change_AreaUnit_AdjustID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _report_Change_AreaUnit_AdjustID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Change_AreaUnit_Adjust::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override bool Delete()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Change_AreaUnit_Adjust_Delete]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_Change_AreaUnit_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_Change_AreaUnit_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Change_AreaUnit_Adjust::Delete::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override DataTable SelectOne()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Change_AreaUnit_Adjust_SelectOne]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_Change_AreaUnit_Adjust");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_Change_AreaUnit_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _report_Change_AreaUnit_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				if(toReturn.Rows.Count > 0)
				{
					_report_Change_AreaUnit_ID = (Guid)toReturn.Rows[0]["Report_Change_AreaUnit_ID"];
					_report_Change_AreaUnit_MainID = (Guid)toReturn.Rows[0]["Report_Change_AreaUnit_MainID"];
					_report_Change_AreaUnit_AdjustID = (Int32)toReturn.Rows[0]["Report_Change_AreaUnit_AdjustID"];
				}
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Change_AreaUnit_Adjust::SelectOne::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Report_Change_AreaUnit_Adjust_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Report_Change_AreaUnit_Adjust");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Report_Change_AreaUnit_Adjust::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Report_Change_AreaUnit_ID
		{
			get
			{
				return _report_Change_AreaUnit_ID;
			}
			set
			{
				_report_Change_AreaUnit_ID = value;
			}
		}


		public SqlGuid Report_Change_AreaUnit_MainID
		{
			get
			{
				return _report_Change_AreaUnit_MainID;
			}
			set
			{
				SqlGuid report_Change_AreaUnit_MainIDTmp = (SqlGuid)value;
				if(report_Change_AreaUnit_MainIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Report_Change_AreaUnit_MainID", "Report_Change_AreaUnit_MainID can't be NULL");
				}
				_report_Change_AreaUnit_MainID = value;
			}
		}


		public SqlInt32 Report_Change_AreaUnit_AdjustID
		{
			get
			{
				return _report_Change_AreaUnit_AdjustID;
			}
			set
			{
				SqlInt32 report_Change_AreaUnit_AdjustIDTmp = (SqlInt32)value;
				if(report_Change_AreaUnit_AdjustIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Report_Change_AreaUnit_AdjustID", "Report_Change_AreaUnit_AdjustID can't be NULL");
				}
				_report_Change_AreaUnit_AdjustID = value;
			}
		}
		#endregion
	}
}
